//
//  YNetworkClient.m
//  Yarhoo
//
//  Created by 杨春至 on 2018/6/6.
//  Copyright © 2018年 Yarhoo. All rights reserved.
//

#import "YNetworkClient.h"
#import "TBinaryProtocol.h"

@interface YNetworkClient()

@property (nonatomic, strong) NSOperationQueue *asyncQueue;
@property (nonatomic, strong) NSOperationQueue *mainQueue;

@end
static NSString *const HOST_URl = @"http://221.7.13.207:8080/chdserver.php";

@implementation YNetworkClient
+ (instancetype)sharedSelf{
    static dispatch_once_t onceToken;
    static YNetworkClient *client = nil;
    dispatch_once(&onceToken, ^{
        client = [[YNetworkClient alloc]init];
    });
    return client;
}
- (instancetype)init{
    
    _asyncQueue = [[NSOperationQueue alloc] init];
    [_asyncQueue setMaxConcurrentOperationCount:1]; // serial
    _mainQueue = [NSOperationQueue mainQueue];
    
    THTTPClient *client = [[THTTPClient alloc]initWithURL:[NSURL URLWithString:HOST_URl]];
    TBinaryProtocol *protocol = [[TBinaryProtocol alloc]
                                 initWithTransport:client
                                 strictRead:YES
                                 strictWrite:YES];
    self = [super initWithProtocol:protocol];
    return self;

}
@end
